#include "../ModelEditorConfig.h"
#include "EditorToolBar.h"
#include "MainFrame.h"

ToolbarListener::ToolbarListener(ModelEditorMainFrame* mainframe_)
{
	mainframe = mainframe_;

	addAndMakeVisible(toolbar = new Toolbar());
	toolbar->addDefaultItems(ToolbarFactory);

	for( int i=0; i<toolbar->getNumItems(); i++ )
	{
		toolbar->getItemComponent(i)->addListener(this);
		if( toolbar->getItemComponent(i)->getButtonText() == String("show resource tree") )
			toolbar->getItemComponent(i)->setToggleState( CModelEditorConfig::GetInstance()->m_UILayout.bShowLeftPanel, false );
		else if( toolbar->getItemComponent(i)->getButtonText() == String("show properties") )
			toolbar->getItemComponent(i)->setToggleState( CModelEditorConfig::GetInstance()->m_UILayout.bShowRightPanel, false );
		else if( toolbar->getItemComponent(i)->getButtonText() == String("show control panel") )
			toolbar->getItemComponent(i)->setToggleState( CModelEditorConfig::GetInstance()->m_UILayout.bShowBottomPanel, false );
	}
}

ToolbarListener::~ToolbarListener()
{
}

void ToolbarListener::resized()
{
	toolbar->setBounds(0,0,getWidth(), getHeight());
}

void ToolbarListener::buttonClicked(Button* buttonThatWasClicked)
{
	if(buttonThatWasClicked->getButtonText() == String("open"))   
	{
		AlertWindow::showMessageBox(AlertWindow::NoIcon, "About Application","Application version 1.00 Beta\nDeveloped by:  Unit, Company");
	}
	else if(buttonThatWasClicked->getButtonText() == String("close"))
	{
		CModelEditorConfig::GetInstance()->CloseScene();
		mainframe->m_pD3DCanvas->m_ControlPanel->ResetUI();
	}
	else if(buttonThatWasClicked->getButtonText() == String("exit"))
	{
		JUCEApplication::getInstance()->systemRequestedQuit();
	}
	else if( buttonThatWasClicked->getButtonText() == String("show resource tree") )
	{
		CModelEditorConfig::GetInstance()->m_UILayout.bShowLeftPanel = !CModelEditorConfig::GetInstance()->m_UILayout.bShowLeftPanel;
		buttonThatWasClicked->setToggleState(CModelEditorConfig::GetInstance()->m_UILayout.bShowLeftPanel, false);
		if( CModelEditorConfig::GetInstance()->m_UILayout.bShowLeftPanel )
			mainframe->ShowLeftPanel();
		else
			mainframe->HideLeftPanel();
	}
	else if( buttonThatWasClicked->getButtonText() == String("show properties") )
	{
		CModelEditorConfig::GetInstance()->m_UILayout.bShowRightPanel = !CModelEditorConfig::GetInstance()->m_UILayout.bShowRightPanel;
		buttonThatWasClicked->setToggleState(CModelEditorConfig::GetInstance()->m_UILayout.bShowRightPanel, false);
		if( CModelEditorConfig::GetInstance()->m_UILayout.bShowRightPanel )
			mainframe->ShowRightPanel();
		else
			mainframe->HideRightPanel();
	}
	else if( buttonThatWasClicked->getButtonText() == String("show control panel") )
	{
		CModelEditorConfig::GetInstance()->m_UILayout.bShowBottomPanel = !CModelEditorConfig::GetInstance()->m_UILayout.bShowBottomPanel;
		buttonThatWasClicked->setToggleState(CModelEditorConfig::GetInstance()->m_UILayout.bShowBottomPanel, false);
		if( CModelEditorConfig::GetInstance()->m_UILayout.bShowBottomPanel )
			mainframe->ShowBottomPanel();
		else
			mainframe->HideBottomPanel();
	}
	else if( buttonThatWasClicked->getButtonText() == String("show setting") )
	{
	}

}